package com.explorati.LinkedList.stack;

import java.util.Random;

public class Main {

	private static double testStack(Stack<Integer> stack, int opCount) {
		Random random = new Random();
		long startTime = System.nanoTime();
		for (int i = 0; i < opCount; i++) {
			stack.push(random.nextInt(Integer.MAX_VALUE));
		}
		for (int i = 0; i < opCount; i++) {
			stack.pop();
		}
		long endTime = System.nanoTime();
		return (endTime - startTime) / 1000000000.0;
	}

	public static void main(String[] args) {
		int opCount = 100000;
		Stack<Integer> arrayStack = new ArrayStack<>();
		double time1 = testStack(arrayStack, opCount);
		System.out.println("数组实现栈 costTime: " + time1);

		Stack<Integer> linkedListStack = new LinkedListStack<>();
		double time2 = testStack(linkedListStack, opCount);
		System.out.println("链表实现栈 costTime: " + time2);

		// 其实这个时间比较复杂，因为LinkedListStack中包含更多的操作
	}
}
